﻿Public Class CINNERDELIVERYState4 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINNERDELIVERYState.IsEnter")
        If CCommon.isInStr(task.ActionCd, "LABEL-ID") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase
        Dim pdaTask As CPDATask4 = DirectCast(task, CPDATask4)
        Debug.WriteLine("CINNERDELIVERYState.DoExecute")
        Dim labelType As String = "DL"
        Dim readText As String = task.ProcessText
        Dim sysItemCd As String = ""
        Dim inBoxQty As Integer = 0
        Dim orderCd As String = ""
        Dim deliveryCd As String = CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_ID_REPORT_CD)
        Dim uniqueCd As String = deliveryCd

        Dim isGroupCd As Boolean = deliveryCd.StartsWith("VG")
        Dim uniqueCdInfo As CPDATask4.strctUniqueCdInfo = Nothing
        If Not isGroupCd Then
            ''読込み済みのラベルではないか確認（ユニークコード）N:アラート
            uniqueCdInfo.labelType = labelType
            uniqueCdInfo.sysItemCd = sysItemCd
            uniqueCdInfo.uniqueCd = uniqueCd
            uniqueCdInfo.readDateTime = Now()
            uniqueCdInfo.empCd = pdaTask.EmpInfo.empNo
        End If

        Dim msg As String = pdaTask.uniqueCdInfoStandardLogic(uniqueCdInfo, False)
        If msg <> "" Then
            ''警告
            pdaTask.alertMsg(msg, task)
        Else

            pdaTask.WindowManager.SetMessage(CCommon.CNS_MSG_005, CCommon.COLOR_BLACK, CCommon.COLOR_GREEN)

            Dim readData() As CPDATask4.strctDataList = Nothing
            Dim Cweb As CWebManager = CWebManager.GetInstance
            Dim altMsg As String = ""
            Dim errRptCd() As String = Nothing
            Dim AppManager As CApplicationManager = CApplicationManager.GetInstance
            Dim ret As String = Cweb.deliveryInfoDownload(deliveryCd, AppManager.GetAppSettings.CompanyCd, readData, isGroupCd, errRptCd, pdaTask)
            Select Case ret
                Case "404"
                    ''正しい出荷指示書ではありません
                    altMsg = CCommon.CNS_MSG_041
                Case "410"
                    ''正しい出荷指示書ではありません
                    altMsg = CCommon.CNS_MSG_041
                Case "412"
                    ''出荷指示書が古い
                    altMsg = CCommon.CNS_MSG_042
                Case "500"
                    ''システムエラー
                    altMsg = CCommon.CNS_MSG_043
                Case "999"
                    ''タイムアウト
                    altMsg = CCommon.CNS_MSG_044
                Case Else
                    ''不明
                    altMsg = CCommon.CNS_MSG_043
            End Select
            If ret = "200" Then
                If Not errRptCd Is Nothing Then
                    Dim i As Integer
                    Dim errRptCdString As String = ""
                    For i = 0 To errRptCd.Length - 1
                        errRptCdString += errRptCd(i) & vbNewLine
                    Next
                    pdaTask.alertMsg(CCommon.msgFormat(CCommon.CNS_MSG_063, errRptCdString), task)
                End If

                pdaTask.listClear()
                pdaTask.addDataList(pdaTask.listView(readData))
                If Not isGroupCd Then
                    pdaTask.addUniqueCdInfo(uniqueCdInfo)
                End If
            Else
                pdaTask.alertMsg(altMsg, task)
            End If
        End If

        task.ActionCd = "LABEL"
        task.ProcessText = ""
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINNERDELIVERYState.DoExit")
        Return True
    End Function

End Class
